package com.zhonghui.dolo.manager.dao.impl;

import com.zhonghui.dolo.manager.dao.GoodsPriceDao;
import com.zhonghui.dolo.manager.dao.mapper.GoodsPriceMapper;
import com.zhonghui.dolo.manager.model.GoodsPrice;
import com.zhonghui.dolo.manager.model.GoodsPriceExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class GoodsPriceDaoImpl implements GoodsPriceDao {
    @Autowired
    private GoodsPriceMapper goodsPriceMapper;
    @Override
    public List<GoodsPrice> queryGoodsPriceListByGoodsId(Integer goodsId) {
        GoodsPriceExample example = new GoodsPriceExample();
        example.createCriteria().andGoodsIdEqualTo(goodsId);
        return goodsPriceMapper.selectByExample(example);
    }

    @Override
    public int updateGoodsPriceList(List<GoodsPrice> goodsPriceList) {
        int result = 0;
        for (GoodsPrice goodsPrice : goodsPriceList) {
           result += goodsPriceMapper.updateByPrimaryKeySelective(goodsPrice);
        }
        return result;
    }

    @Override
    public int batchInsertGoodsPrice(List<GoodsPrice> goodsPriceVoList) {
        int result = 0;
        for (GoodsPrice goodsPrice : goodsPriceVoList) {
            result += goodsPriceMapper.insertSelective(goodsPrice);
        }
        return result;
    }
}
